package com.example.demoes.controller;

import com.example.demoes.entity.OmsOrder;
import com.example.demoes.service.OmsOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author rosszhang
 * @since 2023-12-09
 */
@Api(tags = "订单前端控制器")
@RestController
@RequestMapping("/order")
@RequiredArgsConstructor
public class OmsOrderController {

    private final OmsOrderService omsOrderService;


    @ApiOperation(value = "订单列表")
    @GetMapping("/list")
    public Object list() {
        return this.omsOrderService.list();
    }


    @ApiOperation(value = "往ES添加所有订单")
    @GetMapping("/getList")
    public Object getList() {
        return this.omsOrderService.getEsList();
    }

    @ApiOperation(value = "根据用户名查询订单")
    @GetMapping("/getEs")
    public Object getEs(String memberUsername) {
        return this.omsOrderService.getEs(memberUsername);
    }

    @ApiOperation(value = "根据用户名查询订单,分页")
    @GetMapping("/getEsPage")
    public Object getEsPage(String memberUsername) {
        return this.omsOrderService.getEsQuery(memberUsername);
    }

    @ApiOperation(value = "根据主键ID删除Es中的数据")
    @GetMapping("/deletedEsById")
    public Object deletedEsById(Long id) {
        StringBuffer sb = new StringBuffer();
        long countFirst = this.omsOrderService.countEs();
        sb.append("在删除前总共有：").append(countFirst).append("\n");

        this.omsOrderService.deletedEsById(id);

        long countAfter = this.omsOrderService.countEs();
        sb.append("在删除后总共有：").append(countAfter);
        return sb;

    }

    @ApiOperation(value = "统计Es中所有订单数量")
    @GetMapping("/count")
    public Object count() {
        return this.omsOrderService.countEs();
    }
}
